﻿<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.magical.entity.Files" %>
	<div class="panel panel-default" style="margin-left: 10px; margin-top: 10px">
		<!-- Default panel contents -->
		<div class="btn-group" role="group" id="ooperation"
			 style="margin-left: 10px; margin-top: 20px;">
			<a class="btn btn-default" id="delete" onclick="return deleteDrastically()">彻底删除</a>
			<a class="btn btn-default" id="main-rename" onclick="return recover()">恢复</a>
		</div>
		<div class="panel-heading" id="pathnav" style="margin-top: 5px;">
			<a>回收站</a>
			<%
				Files file=(Files)request.getAttribute("file");
				String ids=(String)request.getAttribute("ids");
				if(file!=null){
					String path=file.getFullPath();
					String[] p=path.split("\\\\");
					String[] id=ids.split("-");
					int index=0;
					for(int i=0;i<p.length;i++){
						if(p[i].equals("upload")) {
							index = i;
							break;
						}
					}
					for(int i=index+2;i<p.length;i++){
			%>
            <a href="/files/search?folderId=<%=id[i-index-1]%>&path=<%=ids%>">  /  <%=p[i]%></a>
			<%
					}
				}
			%>
			<span id="navPath">
			</span>
		</div>

		<table class="table table-hover" id="mytable">
			<thead>
				<tr>
					<th><input id="checkAll" type="checkbox" onclick="swapCheck()" value="+data[i].id+" aria-label="..."></th>
					<th colspan="4" width="60%">文件名</th>
					<th>大小</th>
					<th>刪除时间</th>
				</tr>
			</thead>

			<tbody id="list" >

			</tbody>

		</table>
	</div>

<script src="/js/jquery-1-4-2.min.js"></script>
<script src="/js/public-method.js"></script>
<script>

    $(document).ready(function read(e) {
        showRecycle();
    });
    var isCheckAll = false;
    function swapCheck() {
        if (isCheckAll) {
            $("input[type='checkbox']").each(function() {
                this.checked = false;
            });
            isCheckAll = false;
        } else {
            $("input[type='checkbox']").each(function() {
                this.checked = true;
            });
            isCheckAll = true;
        }
    }
    //显示回收站
	function showRecycle() {
        $.ajax({
            url: "../files/showRecycle",
            type: "POST",
            dataType: 'json',
            data: {},
            success: function (data) {
                var str = "";
                var tbody = window.document.getElementById("list");
                tbody.innerHTML = "";
                for (i in data) {
                    var str = "";
                    var tbody = window.document.getElementById("list");
                    tbody.innerHTML = "";
                    for (i in data) {
                        str += "<tr>" +
                            "<td><input name=\"isSelected\" value=\"" + data[i].fileId + "\" type='checkbox'> </td>" +
                            "<td colspan=\"4\" width=\"60%\">";
                        switch (data[i].filetypeId) {
                            case 1:
                                str += "<img src=\"../img/yyc-images/filetype/mp4.png\" width=\"4%\">" + data[i].fileName + "</td>";
                                break;
                            case 2:
                                str += "<img src=\"../img/yyc-images/filetype/text.png\" width=\"4%\">" + data[i].fileName + "</td>";
                                break;
                            case 3:
                                str += "<img src=\"../img/yyc-images/filetype/mp3.png\" width=\"4%\">" + data[i].fileName + "</td>";
                                break;
                            case 4:
                                str += "<img src=\"../img/yyc-images/filetype/png.png\" width=\"4%\">" + data[i].fileName + "</td>";
                                break;
                            case 5:
                                str += "<img src=\"../img/yyc-images/filetype/icon.png\" width=\"4%\">" + data[i].fileName + "</td>";
                                break;
                            case 6:
                                str += "<img src=\"../img/yyc-images/filetype/other.png\" width=\"4%\">" + data[i].fileName + "</td>";
                                break;
                        }
                        str += "<td>"
						if (data[i].filetypeId == 5) {
                            str += "--";
                        }
                        else {
                            str += data[i].fileFullSize;
                        }"</td>";
                        str += "<td>" + data[i].stringTime + "</td></tr>";
                    }
                }
                tbody.innerHTML += str;

            },
            error: function (data) {
                alert("查找失败");
            }
        });
    }
    //彻底删除
	function deleteDrastically() {
        var obj = document.getElementsByName('isSelected');
        var s1 = "Select:";
        var ids = "";
        for (var i = 0; i < obj.length; i++) {
            if (obj[i].checked) {
                ids += obj[i].value + ","; //如果选中，将value添加到变量s中
                //alert(obj[i].value)
            }
        }
        if (ids == '') {
            alert("请先做选择");
        }
        else {
            layer.msg("文件删除后将无法恢复，您确认要彻底删除所选文件吗？", {
                time: 0
                , btn: ['确定', '取消']
                , yes: function () {
                    $.get("../files/deleteFiles?ids=" + ids, function (data) {
                        if ("success" == data) {
                            layer.msg('已删除', {time: 200000, icon: 1});
                            window.location.reload();
                        }
                        else {
                            alert("Error!");
                        }
                    });
                }, function () {
                    layer.msg('已取消', {
                        time: 4000, //后自动关闭
                    });
                }
            });
        }
    }

    //恢复
	function recover() {
        var obj = document.getElementsByName('isSelected');
        var s1 = "Select:";
        var ids = "";
        for (var i = 0; i < obj.length; i++) {
            if (obj[i].checked) {
                ids += obj[i].value + ","; //如果选中，将value添加到变量s中
                //alert(obj[i].value)
            }
        }
        if (ids == '') {
            alert("请先做选择");
        }
        else {
            layer.msg("确定恢复吗？", {
                time: 0
                , btn: ['确定', '取消']
            ,yes: function () {
                $.get("../files/recovereFiles?ids=" + ids, function (data) {
                    if ("success" == data) {
                        layer.msg('已恢复', {time:200000,icon: 1});
                        window.location.reload();
                    }
                    else {
                        alert("Error!");
                    }
                });
            }, function () {
                layer.msg('已取消', {time: 4000,});
                }
            });
		}
	}
</script>